<?php    // anyco_im.php

require('anyco_cn.inc');
require('anyco_db.inc');
construct_image();

function construct_image()
{
  if (!isset($_GET['showempphoto'])) {
    return;
  }

  $empid = $_GET['showempphoto'];

  $conn = db_connect($err);

  if (!$conn) {
    return;
  }

  $query =
    'SELECT employee_thumbnail
     FROM   employee_photos
     WHERE  employee_id = :eid';

  $stid = oci_parse($conn, $query);
  $r = oci_bind_by_name($stid, ":eid", $empid, -1);
  if (!$r) {
    return;
  }
  $r = oci_execute($stid, OCI_DEFAULT);
  if (!$r) {
    return;
  }

  $arr = oci_fetch_row($stid);
  if (!$arr) {
    return;                     // photo not found
  }

  $result = $arr[0]->load();

  // If any text (or whitespace!) is printed before this header is sent,
  // the text is not displayed. The image also is not displayed properly.
  // Comment out the "header" line to see the text and debug.
  header("Content-type: image/JPEG");
  echo $result;
}

?>

